//
//  BaseApiManager_show.swift
//  Wanke
//
//  Created by BO ZHOU on 2020/10/29.
//

import UIKit

extension BaseApiManager {
    
    class func showLoadingView(showLoading: Bool = true, loadingInView: UIView? = nil) -> NetWorkLoadingView? {
        
        if showLoading {
            
            if let view = loadingInView {

                return view.showNetWorkLoding()
            } else {
                
                if let topcontroller = topViewController() {

                    return topcontroller.showNetWorkLoding()
                }
                // 全部蒙住的效果
//                UIApplication.shared.keyWindow!.showNetWorkLoding()
            }
        }
        
        return nil
    }
    
//    class func hideLoadingView(showLoading: Bool = true, loadingInView: UIView? = nil) {
//        
//        // 没show不需要hide, 否则有些接口自己控制显示loading 会出错
//        if showLoading {
//            if let view = loadingInView {
//
//                view.hideNetWorkLoding()
//            } else {
//                
//                if let topcontroller = topViewController() {
//
//                    topcontroller.hideNetWorkLoding()
//                }
////                UIApplication.shared.keyWindow!.hideNetWorkLoding()
//            }
//        }
//        
//    }
    
    
    class func showErrorView(showError: Bool = true, errorInView: UIView? = nil, task: (()->Void)?) {
        
        if showError {
            if let view = errorInView {

                view.showNetWorkError(clickBlock: task)
            } else {
                
                if let topcontroller = topViewController() {
                    
                    topcontroller.showNetWorkError(clickBlock: task)
                }
            }
        }

    }
    
    
    class func hideErrorView(showError: Bool = true, errorInView: UIView? = nil) {
        
        if let view = errorInView {

            view.hideNetWorkError()
        } else {
            
            if let topcontroller = topViewController() {
                
                topcontroller.hideNetWorkError()
            }
        }
    }
}
